package com.yjhb.android.sbz.mvp.everydaymoney;

import com.yjhb.android.sbz.entity.RedPackDetails;
import com.yjhb.android.sbz.entity.RedPackItem;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2021/1/14 15:36
 */
public class EverydayMoneyPresenter extends ConventionPresenter<EverydayMoneyView> {
    private final String TAG = "EverydayMoneyPresenter";

    @Override
    protected void onDestroy() {

    }

    public EverydayMoneyPresenter(EverydayMoneyView everydayMoneyView) {
        super(everydayMoneyView);
    }

    public void getRedPackList(int size, int current) {
        HttpTool.request(model.getListRedPack(size, current), new HttpObserver<List<RedPackDetails>>() {
            @Override
            public void onResult(List<RedPackDetails> data) {
                if (view != null) {
                    view.onLoad(data, current == 1);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

    public void pullRedPacket(RedPackDetails redPackDetails) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.pullRedPacket(redPackDetails.getTaskId()), new HttpObserver<RedPackItem>() {
            @Override
            public void onResult(RedPackItem data) {
                if (view != null) {
                    view.onOpenSuccess(redPackDetails, data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


    public void queryPullState(RedPackDetails redPackDetails) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.queryPullState(redPackDetails.getTaskId()), new HttpObserver<Integer>() {
            @Override
            public void onResult(Integer data) {
                if (view != null) {
                    view.onState(data,redPackDetails);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

}
